{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第四次练习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "+ 请务必交到exer4文件夹下，谢绝交到master下\n",
    "+ 请不要改动任何文件，拜托\n",
    "+ 请在10月30日前提交。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请写一下姓名和学号：\n",
    "+ 姓名 邓明慧 \n",
    "+ 学号 0165200"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目一\n",
    "一般的歌，分为主歌和副歌部分。副歌有重复，对比两大功能。这就是A－B的基本曲式形式结构。  \n",
    "请找一首你的主打歌，把歌词打印出来，重复的副歌部分，请写一个函数，调用函数打印出来。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "我的主打歌：我也可以是流浪诗人\n",
      "演唱：好妹妹乐队\n",
      "作曲：好妹妹乐队\n",
      "作词：越阳\n",
      "金色的月亮 黑色夜空\n",
      "，黑色的风衣 披着我，\n",
      "喧嚣的城市 匆忙的行人，\n",
      "在南方流浪 在南方歌唱，\n",
      "那就走吧,\n",
      " 谁知道前面是什么\n",
      "那就走吧,\n",
      " 停留在那里风景是一样的\n",
      "那就走吧,\n",
      " 别忘了带上吉他和悲伤外壳\n",
      "大概吧，我也可以是吟游的诗人\n",
      "那就走吧,\n",
      " 谁知道前面是什么\n",
      "那就走吧,\n",
      " 停留在那里风景是一样的\n",
      "那就走吧,\n",
      " 别忘了带上吉他和悲伤外壳\n",
      "大概吧，我也可以是吟游的诗人\n",
      "或许吧，我也可以是流浪的诗人\n"
     ]
    }
   ],
   "source": [
    "print(\"我的主打歌：我也可以是流浪诗人\\n演唱：好妹妹乐队\\n作曲：好妹妹乐队\\n作词：越阳\")\n",
    "print(\"金色的月亮 黑色夜空\\n，黑色的风衣 披着我，\\n喧嚣的城市 匆忙的行人，\\n在南方流浪 在南方歌唱，\")\n",
    "def fu_ge(name):\n",
    "    print(\"那就走吧,\\n %s\" % name)\n",
    "fu_ge(\"谁知道前面是什么\")\n",
    "fu_ge(\"停留在那里风景是一样的\")\n",
    "fu_ge(\"别忘了带上吉他和悲伤外壳\")\n",
    "print(\"大概吧，我也可以是吟游的诗人\")\n",
    "fu_ge(\"谁知道前面是什么\")\n",
    "fu_ge(\"停留在那里风景是一样的\")\n",
    "fu_ge(\"别忘了带上吉他和悲伤外壳\")\n",
    "print(\"大概吧，我也可以是吟游的诗人\")\n",
    "print(\"或许吧，我也可以是流浪的诗人\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目二\n",
    "请写一个函数，能够计算均值、样本方差和n(自己写公式哦)。\n",
    "每次输入十个以上的数字，能够输出上述三个统计量。\n",
    "至少调用两次。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "均值=6.0\n",
      "样本方差=10.0\n",
      "样本个数=11\n",
      "\n",
      "均值=7.3076923076923075\n",
      "样本方差=67.44378698224854\n",
      "样本个数=13\n",
      "\n"
     ]
    }
   ],
   "source": [
    "def nums_function(*nums):\n",
    "    n=0\n",
    "    sum=0\n",
    "    average=0\n",
    "    p=0.0\n",
    "\n",
    "    for num in nums:\n",
    "        sum+=num\n",
    "        n+=1\n",
    "        average=sum/n\n",
    "    for num in nums:\n",
    "        p+=(num-average)**2\n",
    "        \n",
    "    var=p/n\n",
    "    print(\"均值=%s\"%average)\n",
    "    print(\"样本方差=%s\"%var)\n",
    "    print(\"样本个数=%s\\n\"%n)\n",
    "\n",
    "nums_function(1,2,3,4,5,6,7,8,9,10,11)\n",
    "nums_function(3,4,5,6,1,2,3,4,5,7,9,12,34)\n",
    "    \n",
    "   "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 题目三\n",
    "刚才那个函数，默认的是输出均值、样本方差和n，请在后面添加一个关键词参数，让这个函数可以选择输出样本标准差或方差。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "均值=6.0\n",
      "样本个数=11 \n",
      "\n",
      "样本标准差请输入1，样本方差请输入21\n",
      "样本标准差=3.1622776601683795 \n",
      "\n",
      "均值=7.3076923076923075\n",
      "样本个数=13 \n",
      "\n",
      "样本标准差请输入1，样本方差请输入22\n",
      "样本方差=67.44378698224854\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "def nums_function(*nums,**value):\n",
    "    n=0\n",
    "    sum=0\n",
    "    average=0\n",
    "    p=0.0\n",
    "\n",
    "    for num in nums:\n",
    "        sum+=num\n",
    "        n+=1\n",
    "        average=sum/n\n",
    "    for num in nums:\n",
    "        p+=(num-average)**2\n",
    "    var=p/n\n",
    "    print(\"均值=%s\"%average)\n",
    "    print(\"样本个数=%s \\n\"%n)\n",
    "    value=int(input(\"样本标准差请输入1，样本方差请输入2\"))\n",
    "    if value==1:\n",
    "        print('样本标准差=%s \\n'%math.sqrt(var))       \n",
    "    else:\n",
    "        print(\"样本方差=%s\"%var)    \n",
    "nums_function(1,2,3,4,5,6,7,8,9,10,11)\n",
    "nums_function(3,4,5,6,1,2,3,4,5,7,9,12,34)       \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 题目四\n",
    "刚才那个函数，请再增加三个关键词参数，让这个参数可以选择输出均值的标准误、最大值、最小值或不输出这三个统计量。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "均值=7.5\n",
      "样本个数=8\n",
      "样本标准差请输入1，样本方差请输入21\n",
      "样本标准差=2.29128784747792\n",
      "选择输出标准误请输入1，不输出请输入21\n",
      "标准误=1.8561553006146871\n",
      "选择输出最大值请输入1，不输出请输入21\n",
      "最大值=11\n",
      "选择输出最小值请输入1，不输出请输入21\n",
      "最小值=4\n",
      "\n",
      "均值=8.3\n",
      "样本个数=10\n",
      "样本标准差请输入1，样本方差请输入21\n",
      "样本标准差=9.121951545584968\n",
      "选择输出标准误请输入1，不输出请输入21\n",
      "标准误=26.313312410261084\n",
      "选择输出最大值请输入1，不输出请输入21\n",
      "最大值=34\n",
      "选择输出最小值请输入1，不输出请输入21\n",
      "最小值=1\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "def nums_function(a,b,c,*nums,**value):\n",
    "    n=0\n",
    "    sum=0\n",
    "    average=0\n",
    "    p=0.0\n",
    "\n",
    "    for num in nums:\n",
    "        sum+=num\n",
    "        n+=1\n",
    "        average=sum/n\n",
    "    for num in nums:\n",
    "        p+=(num-average)**2\n",
    "    var=p/n\n",
    "    print(\"均值=%s\"%average)\n",
    "    print(\"样本个数=%s\"%n)\n",
    "    \n",
    "    value=int(input(\"样本标准差请输入1，样本方差请输入2\"))\n",
    "    if value==1:\n",
    "        print('样本标准差=%s'%math.sqrt(var))       \n",
    "    else:\n",
    "        print(\"样本方差=%s\\n\"%var)\n",
    "        \n",
    "    a=int(input(\"选择输出标准误请输入1，不输出请输入2\"))\n",
    "    if a==1:\n",
    "        print(\"标准误=%s\"%(var/math.sqrt(n)))\n",
    "    else:\n",
    "        print(\"不输出\")\n",
    "    b=int(input(\"选择输出最大值请输入1，不输出请输入2\"))\n",
    "    if a==1:\n",
    "        print(\"最大值=%s\"%max(nums))\n",
    "    else:\n",
    "        print(\"不输出\")\n",
    "    c=int(input(\"选择输出最小值请输入1，不输出请输入2\"))\n",
    "    if c==1:\n",
    "        print(\"最小值=%s\\n\"%min(nums))\n",
    "    else:\n",
    "        print(\"不输出\\n\")\n",
    "nums_function(1,2,3,4,5,6,7,8,9,10,11)\n",
    "nums_function(3,4,5,6,1,2,3,4,5,7,9,12,34)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
